//做到类似跳转
function GoDetail(article_id) {

    /**
     * *****************************************函数调用****************************************
     */
    get_details(article_id)

    BindgetComment(article_id)
//绑定发表评论功能
    setComInput()


    /**
     * 绑定发表评论功能
     */
    function setComInput() {
        document.querySelector('#discuss_input_btn').onclick = function () {
            let content = document.querySelector('#discuss_input_value').value;
            setComment(content, article_id)
        }
    }

    /**
     * 绑定获取评论功能
     * @param article_id
     * @constructor
     */
    function BindgetComment(article_id) {
        getComments(article_id)

    }


    /**
     * ***********************************数据处理函数**********************************************
     */
    /**
     * 写入评论
     * @param content
     * @param article_id
     */
    function setComment(content, article_id) {
        future.ajax({
            url: '/article/setComment',
            type: 'post',
            data: {
                content,
                article_id
            },
            success: function (result) {
                console.log(result)
                alert("发表评论成功")
                getComments(article_id)
            }
        })

    }

    /**
     * 获取评论且分页倒叙获取
     */
    function getComments(article_id) {

        future.ajax({
            url: '/article/getComment',
            type: 'post',
            data: {
                article_id,

            },
            success: function (result) {
                add_Comments(result)
            }
        })

    }


    /**
     * 渲染评论
     * @param result
     */
    function add_Comments(result) {
        console.log(result)
        let add_comm = ``;
        result.forEach((item, index) => {
            // getUsernameChangeName(item.u_id)
            item.time = rTime(item.time)
            let User;
            let Users = getUserAllsChangeComm(item.u_id, User);
            let imgUrl = "../../file/" + Users.head
            add_comm += `
           <li>
                    <div class="discuss_list_user">
                        <div class="discuss_list_user_img">
                            <img src="` + imgUrl + `" alt="" id="discuss_list_user_img">
                        </div>
                        <div class="discuss_list_user_text">
                            <span id="discuss_list_user_name" >` + Users.username + `</span>
                            <i id="discuss_list_time">` + item.time + `</i>
                        </div>
                        <div></div>
                    </div>
                    <div class="discuss_list_text" id="discuss_list_text">
                        <p>
                            ` + item.content + `
                        </p>
                    </div>
                    <div class="discuss_list_text_hidden"></div>
                </li>
      `

            document.querySelector('#index_details_discuss_list').innerHTML = add_comm
            return add_comm;


        })
    }


    /**
     * 传入用户id搜索用户信息渲染评论
     * @param u_id
     */
    function getUserAllsChangeComm(u_id, User) {

        future.ajax({
            url: '/users/getUserAll',
            type: 'post',
            data: {
                u_id,

            },
            success: function (result) {
                User = result
            }
        })
        return User
    }


    /**
     * 传入用户id搜索用户信息,渲染
     * @param u_id
     */
    function getUserAll(u_id) {
        future.ajax({
            url: '/users/getUserAll',
            type: 'post',
            data: {
                u_id,

            },
            success: function (result) {
                add_auto(result)


            }
        })
    }

    /**
     * 详情页面
     * @param art_id 文章id
     */
    function get_details(article_id) {
        future.ajax({
            url: '/article/getDetails',
            type: 'get',
            data: {
                article_id,
            },
            success: function (result) {
                add_details(result[0])
                getUserAll(result[0].u_id)
            }
        })
    }


    /**
     * *************************************渲染函数*********************************************/


    /**
     * 渲染详情页面作者信息
     * @param result
     */
    function add_auto(result) {
        document.querySelector('#index_details_footer_name').innerText = result.username
        document.querySelector('#index_details_discuss_user_img').src = "../../file/" + result.head
        document.querySelector('#index_details_discussp_user_span1').innerText = result.username
        document.querySelector('#index_details_discussp_user_span2').innerText = result.mailbox
    }


    /**
     * 详情页面渲染函数
     * @param result
     */
    function add_details(result) {
        let add_deta = ``;
        result.time = rTime(result.time)
        document.querySelector('#index_details_title').innerHTML = `
      <span>` + result.title + `</span>`
        document.querySelector('#index_details_footer').innerHTML = `
   <x class="iconfont icon-zuozhe"></x> <i id="index_details_footer_name">洪吉林</i>
            <x class="iconfont icon-riqi"></x><i>` + result.time + `</i>
            <x class="iconfont icon-chakan"></x><i>` + result.hits + `点击量</i>
`
        document.querySelector('#index_details_text').innerHTML = result.content + `  <div class="footerP"></div>`

    }

    /**
     * json字符串转数组
     * @param str
     * @returns {any}
     * @constructor
     */
    function JsonstrToArr(str) {
        let arr = str.split(',');
        let s = JSON.parse(arr)
        return s;
    }

    /**
     * 转换时间格式
     * @param date
     * @returns {string}
     */
    function rTime(date) {
        var json_date = new Date(date).toJSON();
        return new Date(new Date(json_date) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
    }
}